﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;

/// <summary>
/// Summary description for REC
/// </summary>
/// 

namespace Bestlife.ERP.BusinessRules
{


    public class REC
    {
        String usr;
        string c_status;


        public REC()
        {

            String userId;
            String parentId;
           
            //
            // TODO: Add constructor logic here
            //
        }


        public Double recr(String id,String User_Status )
        {
              Double count = 0;
              Double total = 0;
           // int Num_of_Agent;
           // int Num_of_Agent;


           // String parentsql = "SELECT Sup_ID FROM Distributor ";

            String ssql = "SELECT count(*),b.user_id,d.Sup_ID FROM Bonus b,Distributor d WHERE b.user_Status='" + User_Status + "' AND b.user_id =d.Sup_ID";

            try
            {//try

                String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
                Bestlife.ERP.DataAccess.clsCon.connect(connStr);

                SqlDataReader rdrssql;
                rdrssql = Bestlife.ERP.DataAccess.clsCon.ReadTable(ssql);

                while (rdrssql.Read())
                {
                    // parentID = rdRStatus["user_Status"].ToString();

                    usr = rdrssql["User_id"].ToString();
                    count = Double.Parse(rdrssql["User_id"].ToString());
                    c_status = rdrssql["user_Status"].ToString();
                }


                if (count == 0)
                {
                    total = count + total;
                   // break
                    
                }

                  else
                {
                    recr(usr, c_status);
                }


            }//try
            catch (Exception ex)
            {
            }
            return total;
        }


    }

}